clear; clc; close all

p = 100;
n = 1000;
x = rand(n,p);

lrcols = find(rand(1,p) < 0.5);
x(:,lrcols) = rand(n,length(lrcols)) < 0.5;

y = zeros(n,1);
coeff = zeros(n,1);
for i = 1:p,
    coeff(i) = round(10*(rand-0.5));
    y = y + coeff(i)*x(:,i);
end

y = y + 15 + rand(n,1);
fname = 'C:\Users\Mittal\Documents\Work\Code\imputation\C\codebase\CCD\Release\test-ls2.txt';
fp = fopen(fname,'w');
fprintf(fp,'"infert.stratum","infert.case","infert.intercept"');
for j = 1:p,
    arr = [char(65:90) char(97:122)];
    randstr = arr(ceil(rand(1,5)*51));
    if(j < p)
        fprintf(fp,'infert.%s, ',randstr);
    else
        fprintf(fp,'infert.%s\n',randstr);
    end
end
data = [[1:n]' y ones(n,1) x];
for i = 1:n,
    line = data(i,:);
    line = sprintf('%.3f,' , line);
    line = line(1:end-1);
    commas = find(line == ',');
    randThresh = rand;
    indsNA = find(rand(1,length(commas)-8) < randThresh) + 7;
    for j = 1:length(indsNA),
        commas = find(line == ',');
        line = [line(1:commas(indsNA(j))) 'NA' line(commas(indsNA(j)+1):end)];
    end
    fprintf(fp,'%s\n',line);
end
% dlmwrite(fname,data,'delimiter',',','-append');

fclose(fp);